package com.qdsg.ysg.doctor.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qdsg.ysg.doctor.R;
import com.rest.response.PrescriptionResponse;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by HP on 2020/3/2.
 */

public class AddMedicineAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<PrescriptionResponse.Prescription> list;


    public AddMedicineAdapter(Context context, List<PrescriptionResponse.Prescription> list) {
        this.mContext = context;
        this.list = list;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from( parent.getContext() )
                .inflate( R.layout.item_add_medicine, parent, false );
        return new ViewHolder( view );

    }

    @SuppressLint({"NotifyDataSetChanged", "SetTextI18n"})
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        final ViewHolder mHolder = (ViewHolder) holder;
        mHolder.tvMedicineName.setText( list.get( position ).name );
//        mHolder.tvMedicineBaseNum.setText( list.get( position ).drugFrequency + "  " + list.get( position ).drugDose + list.get( position ).specialUnit + "/次" + "   " + list.get( position ).drugChannel );
        mHolder.tvMedicineBaseNum.setText( list.get( position ).drugFrequency + "  " + list.get( position ).drugDose  + "   " + list.get( position ).drugChannel );
        mHolder.tvMedicineNum.setText( list.get( position ).drugNumber );
        mHolder.tvMedicinePrice.setText( list.get( position ).expense );
        mHolder.btnDel.setOnClickListener( v -> {
            list.remove( position );
            notifyDataSetChanged();
        } );
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_medicine_name)
        TextView tvMedicineName;
        @BindView(R.id.tv_medicine_base_num)
        TextView tvMedicineBaseNum;
        @BindView(R.id.tv_medicine_num)
        TextView tvMedicineNum;
        @BindView(R.id.tv_medicine_price)
        TextView tvMedicinePrice;
        @BindView(R.id.btn_del)
        ImageView btnDel;

        ViewHolder(View itemView) {
            super( itemView );
            ButterKnife.bind( this, itemView );
        }
    }


}
